﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Way.Bus.Model;
using Acc.ECharts;
using Acc.Contract.MVC;
using System.Data;
using Way.EAP.DataAccess.Data;

namespace Way.Bus.Wms.Controllers
{
    public class SearchController : ControllerBase
    {
        public SearchController() : base(new BusinessBase()) { }

        public series[] getsfh()
        {
            List<double> sl = new List<double>(12);
            List<double> fl = new List<double>(12);
            for (int i = 0; i < 12; i++)
            {
                sl.Add(0); fl.Add(0);
            }
            string sql = "select Createdby,y,m,sum(num) num from ("
+ " select YEAR(Creationdate) y,MONTH(Creationdate) m,Createdby,num from {0}) a where Createdby={1} and y=" + DateTime.Now.Year
+ " group by Createdby,y,m";
            IDataAction action=this.model.GetDataAction();
            DataTable st = action.GetDataTable(string.Format(sql, "Acc_WMS_InOrderMaterials", this.user.ID));
            if (st != null)
            {
                foreach (DataRow r in st.Rows)
                {
                    int i = int.Parse(r["m"].ToString());
                    sl[i-1] = double.Parse(r["num"].ToString());
                }
            }
            DataTable ft = action.GetDataTable(string.Format(sql, "Acc_WMS_outOrderMaterials", this.user.ID));
            if (ft != null)
            {
                foreach (DataRow r in ft.Rows)
                {
                    int i = int.Parse(r["m"].ToString());
                    fl[i-1] = double.Parse(r["num"].ToString());
                }
            }
            series sse = new series("bar");
            sse.data = sl.ToArray();
            sse.name = "收货数量";
            series fse = new series("bar");
            fse.data = fl.ToArray();
            fse.name = "发货数量";
            List<series> list = new List<series>();
            list.Add(sse); list.Add(fse);
            return list.ToArray();
        }

    }
}
